{% from "header.jinja" import header %}

"""{{ header() }}"""

from weakref import ref
from typing import TYPE_CHECKING
from functools import cached_property

if TYPE_CHECKING:
    from githubkit import GitHubCore
    {% for tag in tags %}
    from .{{ tag }} import {{ pascal_case(tag) }}Client
    {% endfor %}


class RestNamespace:
    def __init__(self, github: "GitHubCore"):
        self._github_ref = ref(github)

    @property
    def _github(self) -> "GitHubCore":
        if g := self._github_ref():
            return g
        raise RuntimeError(
            "GitHub client has already been collected. "
            "Do not use this namespace after the client has been collected."
        )

    {% for tag in tags %}
    @cached_property
    def {{ tag }}(self) -> "{{ pascal_case(tag) }}Client":
        from .{{ tag }} import {{ pascal_case(tag) }}Client

        return {{ pascal_case(tag) }}Client(self._github)
    {% endfor %}
